package main

import "fmt"

func main() {
	s := "A man, a plan, a canal: Panama"
	//s = "race a car"
	//s = "0P"
	v := isPalindrome(s)
	fmt.Println(v)
}

func isPalindrome(s string) bool {
	sByte := []byte(s)
	l := 0
	r := len(sByte) - 1
	for l < r {
		for !isChar(sByte[l]) && !isNum(sByte[l]) && l < r {
			l++
		}
		for !isChar(sByte[r]) && !isNum(sByte[r]) && l < r {
			r--
		}

		if isChar(sByte[l]) != isChar(sByte[r]) {
			return false
		}

		var diff byte
		if sByte[l] > sByte[r] {
			diff = sByte[l] - sByte[r]
		} else {
			diff = sByte[r] - sByte[l]
		}

		if diff != 0 && diff != 32 {
			return false
		}
		l++
		r--
	}
	return true
}

func isChar(c byte) bool {
	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
}
func isNum(c byte) bool {
	return c >= '0' && c <= '9'
}
